package com.tsingteng.cosfun.ui.cosfun.presenter;

import android.util.Log;

import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.FollowBean;
import com.tsingteng.cosfun.bean.ParagraphBean;
import com.tsingteng.cosfun.bean.PersonBean;
import com.tsingteng.cosfun.bean.PullBlackBean;
import com.tsingteng.cosfun.bean.VidePersonBean;
import com.tsingteng.cosfun.bean.WorkBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.ui.cosfun.contract.PersonCenterContract;
import com.tsingteng.cosfun.ui.cosfun.imodel.PersonCenterModel;
import com.tsingteng.cosfun.utils.DataUtil;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PersonCenterPresenter extends BasePresenter<PersonCenterContract.IPersonCenterView> implements PersonCenterContract.IPersonInfo {

    PersonCenterModel personCenterModel = null;
    PersonCenterContract.IPersonCenterView iPersonCenterView = null;

    public PersonCenterPresenter(PersonCenterContract.IPersonCenterView iPersonCenterView) {
        this.personCenterModel = new PersonCenterModel();
        this.iPersonCenterView = iPersonCenterView;
    }
    @Override
    public void getPersonInfo(long profileId) {
//        iPersonCenterView.showLoading("");
        Callback<BaseDataBean<PersonBean>> callback = new Callback<BaseDataBean<PersonBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<PersonBean>> call, Response<BaseDataBean<PersonBean>> response) {
                iPersonCenterView.hideLoading();
                iPersonCenterView.showLogonResult(response.body());
            }

            @Override
            public void onFailure(Call<BaseDataBean<PersonBean>> call, Throwable t) {
                iPersonCenterView.hideLoading();
            }
        };
        personCenterModel.getPersonInfo(profileId, callback);
    }

    @Override
    public void getParagraphList(long userId, String c, String showType, String page_no, String page_size, String deviceId) {
        iPersonCenterView.showLoading("");
        Callback<BaseDataBean<ParagraphBean>> paraCallback = new Callback<BaseDataBean<ParagraphBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<ParagraphBean>> call, Response<BaseDataBean<ParagraphBean>> response) {
                iPersonCenterView.hideLoading();

            }

            @Override
            public void onFailure(Call<BaseDataBean<ParagraphBean>> call, Throwable t) {
                iPersonCenterView.hideLoading();
            }
        };
        personCenterModel.getParagraphList(userId, c, showType, page_no, page_size, deviceId, paraCallback);
    }

    @Override
    public void getWorkList(long userId, String c, String showType, String page_no, String page_size, String deviceId) {
        iPersonCenterView.showLoading("");
        Callback<BaseDataBean<VidePersonBean>> workCallback = new Callback<BaseDataBean<VidePersonBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<VidePersonBean>> call, Response<BaseDataBean<VidePersonBean>> response) {
                iPersonCenterView.hideLoading();

            }

            @Override
            public void onFailure(Call<BaseDataBean<VidePersonBean>> call, Throwable t) {
                iPersonCenterView.hideLoading();
            }
        };
        personCenterModel.getWorkList(userId, c, showType, page_no, page_size, deviceId, workCallback);
    }

    @Override
    public void getReadPullBlackState(int user_id) {
        iPersonCenterView.showLoading("");
        Callback<PullBlackBean> workCallback = new Callback<PullBlackBean>() {
            @Override
            public void onResponse(Call<PullBlackBean> call, Response<PullBlackBean> response) {
                iPersonCenterView.hideLoading();
                if (response != null) {
                    PullBlackBean body = response.body();
                    if (body != null) {
                        int data = body.getData();
                        iPersonCenterView.showReadPullBlackStateResult(data);
                    }
                }

            }

            @Override
            public void onFailure(Call<PullBlackBean> call, Throwable t) {
                iPersonCenterView.hideLoading();
            }
        };
        personCenterModel.getReadPullBlackStateInfo(user_id, workCallback);
    }

    @Override
    public void getPullBlack(int user_id) {
        iPersonCenterView.showLoading("");
        Callback<PullBlackBean> workCallback = new Callback<PullBlackBean>() {
            @Override
            public void onResponse(Call<PullBlackBean> call, Response<PullBlackBean> response) {
                iPersonCenterView.hideLoading();
                PullBlackBean body = response.body();
                int data = body.getData();
                iPersonCenterView.showPullBlackResult(data);
            }

            @Override
            public void onFailure(Call<PullBlackBean> call, Throwable t) {
                iPersonCenterView.hideLoading();
            }
        };
        personCenterModel.getPullBlackInfo(user_id, workCallback);
    }

    @Override
    public void getCancelPullBlack(int user_id) {
        iPersonCenterView.showLoading("");
        Callback<PullBlackBean> workCallback = new Callback<PullBlackBean>() {
            @Override
            public void onResponse(Call<PullBlackBean> call, Response<PullBlackBean> response) {
                iPersonCenterView.hideLoading();
                PullBlackBean body = response.body();
                int data = body.getData();
                iPersonCenterView.showCancelPullBlack(data);
            }

            @Override
            public void onFailure(Call<PullBlackBean> call, Throwable t) {
                iPersonCenterView.hideLoading();
                Log.e("/////", t.getMessage());
            }
        };
        personCenterModel.getCancelPullBlackInfo(user_id, workCallback);
    }

    @Override
    public void loginFollowFans(String follow_id) {
        iPersonCenterView.showLoading("");
        Callback<BaseDataBean<FollowBean>> rxObserver = new Callback<BaseDataBean<FollowBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<FollowBean>> call, Response<BaseDataBean<FollowBean>> response) {
                iPersonCenterView.getFollowResult(response.body().data);
                iPersonCenterView.hideLoading();
            }

            @Override
            public void onFailure(Call<BaseDataBean<FollowBean>> call, Throwable t) {
                iPersonCenterView.hideLoading();

            }


        };

        personCenterModel.getFollowNotification(follow_id, rxObserver);
    }

    @Override
    public void loginNoFollow(String follow_id) {
        iPersonCenterView.showLoading("");
        Callback<BaseDataBean<FollowBean>> rxObserver = new Callback<BaseDataBean<FollowBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<FollowBean>> call, Response<BaseDataBean<FollowBean>> response) {
                iPersonCenterView.getNoFollowResult(response.body().data);
                iPersonCenterView.hideLoading();
            }

            @Override
            public void onFailure(Call<BaseDataBean<FollowBean>> call, Throwable t) {
                iPersonCenterView.hideLoading();
            }


        };
        personCenterModel.getNoFollowNotification(follow_id, rxObserver);
    }

}
